package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.entity.Customer;
import com.atguigu.jxc.entity.Supplier;
import com.atguigu.jxc.service.CustomerSerivce;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

/**
 * @description 客户Controller
 */
@Controller
@RequestMapping("/customer")
public class CustomerController {

    @Autowired
    private CustomerSerivce customerSerivce;

    /**
     * 客户列表分页（名称模糊查询）
     * @param page
     * @param rows
     * @param customerName
     * @return
     */
    @PostMapping("/list")
    @ResponseBody
    @RequiresPermissions(value = "客户管理")// 有客户管理菜单权限的才给予调用
    public Map<String, Object> list(Integer page, Integer rows, String customerName) {
        return customerSerivce.list(page, rows, customerName);
    }

    /**
     * 添加或修改客户信息
     * @param customer
     * @return
     */
    @PostMapping(value = "/save")
    @ResponseBody
    @RequiresPermissions(value = "客户管理")
    public ServiceVO save(Customer customer) {
        return customerSerivce.save(customer);
    }

    /**
     * 删除客户信息
     * @param ids
     * @return
     */
    @PostMapping("/delete")
    @ResponseBody
    @RequiresPermissions(value = "客户管理")
    public ServiceVO delete(String ids) {
        String[] id = ids.split(",");
        return customerSerivce.delete(id);
    }
}
